package main

import (
	"github.com/astaxie/beego/validation"
	"log"
	"time"
)

type Users struct {
	Name string `form:"name" json:"name" valid:"Required;Match(/^[-_a-zA-Z0-9一-龥]{1,64}$/)" label:"名称"`
	Age  *uint8 `form:"age" json:"age" valid:"Range(1,150)" label:"年龄"`
	Ad   *Ad    `json:"ad"`
}

type Ad struct {
	Num int `json:"num" valid:"Range(1,3)"`
}

func (u *Users) Valid(v *validation.Validation) {
	log.Println("aaaaaaaaaaaaaa")
	_, err := v.Valid(&u.Ad)
	if err != nil {
		v.AddError("validator error", err.Error())
		return
	}
}

func (u *Users) A() {

}

func main() {
	t, err := time.ParseInLocation("2006-01-02", "2020-01/01", time.Local)
	log.Println(t.After(time.Now()), err)
	users := &Users{
		Name: "年_",
	}
	v := validation.Validation{}
	log.Println(v.MaxSize(users.Name, 1, "").Ok)
	//valid := validation.Validation{}
	//if val.Elem().MethodByName("Valid").IsValid() {
	//	param := make([]reflect.Value, 0)
	//	param = append(param, reflect.ValueOf(&valid))
	//	val.Elem().MethodByName("Valid").Call(param)
	//}
	//ok, err := valid.Valid(users)
	//if err != nil {
	//	return
	//}
	//if ok {
	//	return
	//}
	//
	//result := &validation.Result{}
	//result.Message("yyyyyyy")
	//valid.AddError("1", "aaaa")
	//valid.AddError("1", "vvv")
	//valid.AddError("1", "bbb")
	//valid.AddError("1", "ccc")
	//for k, errs := range valid.ErrorMap() {
	//	for _, err := range errs {
	//		log.Println(err.Key, "---------", k, err.String())
	//	}
	//}
}
